package com.easyj.admin.sys.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.easyj.admin.db.model.Department;
import com.easyj.admin.sys.service.DepartmentService;
import com.easyj.base.common.ajax.Result;
import com.easyj.base.controller.BaseController;
import com.easyj.base.security.SimpleUser;


/**
 * 基础数据
 * @author hjf
 *
 */
@RestController
@RequestMapping(value = "/basedata")
public class BaseDataController   extends BaseController{
	
	
	@Autowired
	private  DepartmentService departmentService;
	


	/**
	 * 取得公司名称，
	 */
    @GetMapping("getCompanyName")
    public Result getCompanyName() {
    	 String name="";
    	try {
    		SimpleUser p=(SimpleUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    		Long depId=p.getDepartmentId();
    		Department dept=departmentService.findById(depId);
    		if(dept!=null) {
 			   if(dept.getType()==1) {
 				   name=dept.getName();
 				  
 			   }else {
 				   name=dept.getCompanyName();
 			   }
 		   }
    	}catch(Exception ex) {
    		name="";
    	}
        return Result.Success(name);
    }

	
	
	
}
